package com.leibun.gpstoggle;

import android.app.Service;
import android.content.Intent;
import android.content.res.Resources;
import android.os.IBinder;
import android.widget.Toast;

public class GpsToggleService extends Service {

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);

		Resources res = getResources();

		try {
			GpsToggleUtil.toggleGps(this);
			boolean state = GpsToggleUtil.getGpsState(this);
			String stateText = state ? res.getString(R.string.gps_on) : res
					.getString(R.string.gps_off);
			Toast.makeText(this, stateText, Toast.LENGTH_LONG).show();

		} catch (Exception e) {
			Toast.makeText(
					this,
					res.getString(R.string.service_error_message)
							+ e.toString(), Toast.LENGTH_LONG).show();
		}

		GpsToggleUtil.notifyGpsState(this);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

}
